﻿@model AddressModel
@using Logistics.Web.Models.Common
@using Logistics.Web.Models.Order;
@using Telerik.Web.Mvc.UI;
@using Telerik.Web.Mvc.Extensions;
<div class="window order-form">
    <div class="window-title grad-lightgrey grad">
        <div class="window-title-bar grad-titleshine grad">
            @{
                // +string+
                bool hasPendingOrder = (bool)ViewBag.HasPendingOrderKey;
            }
            <h2>My HUB for @Model.FirstName @Model.LastName</h2>

        </div>
    </div>

    @using (Html.BeginForm())
    {
        <div class="window-content space myhub">
            <h3>@ViewBag.AccountType</h3>
            @if (!String.IsNullOrEmpty(ViewBag.AccountWarning))
            {
                <h4 style="color:red">@ViewBag.AccountWarning</h4>
            }
            @if (!String.IsNullOrEmpty(ViewBag.PreferredPaymentMethod))
            {
                <h4>@ViewBag.PreferredPaymentMethod</h4>
            }
            <br />
            @if (Model.Company != null)
            {
                <h3>@Html.DisplayFor(model => model.Company)</h3>
            }
            else
            {
                <h3>@Html.DisplayFor(model => model.FirstName) @Html.DisplayFor(model => model.LastName)</h3>
            }

            <div class="hub-left">
                @if (Model.Company != null)
                {
                    <div class="hub-name"><strong>@Html.DisplayFor(model => model.FirstName) @Html.DisplayFor(model => model.LastName)</strong></div>
                }
                <div class="hub-address">@Html.DisplayFor(model => model.Address1) @Html.DisplayFor(model => model.Address2)</div>
                <div class="hub-location">@Html.DisplayFor(model => model.City), @Html.DisplayFor(model => model.StateProvinceName) @Html.DisplayFor(model => model.CountryName) @Html.DisplayFor(model => model.ZipPostalCode)</div>
                @if (Model.Email != null)
                {
                    <div class="hub-email">
                        <label>@Html.LabelFor(model => model.Email):</label>
                        @Html.DisplayFor(model => model.Email)
                    </div>
                }
            </div>
            <div class="hub-center">
                @{
                // +string+
                }
                
                @if (Model.CellPhoneNumber != null)
                {
                    <div class="hub-phone">
                        <label>@Html.LabelFor(model => model.CellPhoneNumber):</label>
                        <span class="hub-cellphone-display">
                            <span class="value">
                                @Html.DisplayFor(model => model.CellPhoneNumber)
                            </span>
                        </span>
                    </div>
                }

                @if (Model.PhoneNumber != null)
                {
                    <div class="hub-phone">
                        <label>@Html.LabelFor(model => model.PhoneNumber):</label>
                        <span class="hub-phone-display">
                            <span class="value">
                                @Html.DisplayFor(model => model.PhoneNumber)
                            </span>
                        </span>
                    </div>
                }
            </div>
            <div class="clear-block"></div>
        </div>
        <div class="hub-bottom">
            <div class="hub-bottom-links">
                @if (hasPendingOrder)
                {
                    @Html.ActionLink("Discard and Create New", "DiscardPendingOrder", null, new { @class="button button-grey discard" });
                    @Html.ActionLink("Continue Saved Order", "OrderInfo", null, new { @class = "button button-red" });
                }
                else
                {
                    @Html.ActionLink("Place New Order", "OrderInfo", null, new { @class = "button button-red" });
                }
            </div>
        </div>
        <script type="text/javascript">
            if (!$.support.leadingWhitespace) {
                $(".window.order-form").before('<div class="general-warning"><strong>Alert: </strong>We have detected that your web browser may be outdated. In order to enhance your browsing experience and order security, please update your web browser to one of the following options immediately: <a href="http://www.mozilla.org/en-US/firefox/new/">Firefox</a>, <a href="https://www.google.com/intl/en/chrome/browser/">Google Chrome</a>, <a href="http://windows.microsoft.com/en-CA/internet-explorer/download-ie">Inernet Explorer 9 or later</a>, or <a href="http://support.apple.com/downloads/#safari">Safari</a>.');
            }

            $('.ajax-notification-decline').live("click", function () {
                $('#ajax-notification, .ajax-loading-box').fadeOut();
            });

            $('.hub-bottom input[type=submit]').click(function (e) {
                var clickedButton = $(this);
                $('.clicked').removeClass(".clicked").show();
                $('#ajax-loading-bar').hide();
                clickedButton.addClass("clicked");
                $('#ajax-loading-bar').show().css({
                    "display": clickedButton.css("display"),
                    "width": clickedButton.outerWidth(),
                    "height": clickedButton.outerHeight(),
                    "margin-top": clickedButton.css("margin-top"),
                    "margin-bottom": clickedButton.css("margin-bottom"),
                    "margin-left": clickedButton.css("margin-left"),
                    "margin-right": clickedButton.css("margin-right")
                }).insertAfter(clickedButton);
                clickedButton.hide();
                if (clickedButton.hasClass('discard')) {
                    $('.ajax-loading-wrapper').hide();
                    $('.ajax-loading-box .title').html('<h2><span class="red">Spots</span>HUB</h2>');
                    $('.ajax-loading-box .content').html('<p>Discarding the current order will remove ALL packages from this order. Would you like to continue and place a new order?</p><div class="ajax-notification-buttons two"><a class="ajax-notification-continue button-red">Yes</a><a class="ajax-notification-decline button-grey">No</a></div>');
                    $('#ajax-notification, .ajax-loading-box').fadeIn(function () {
                        clickedButton.show();
                        $('#ajax-loading-bar').hide();
                    });
                    $('.ajax-notification-continue').click(function () {
                        $('.ajax-loading-box, #ajax-notification').fadeOut(function () {
                            $('.order-form form').append('<input type="hidden" class="discard-submit" name="discard" value="submit" />').submit();
                            /*$('.ajax-loading-box .title').html('<img src="/Content/images/spotsexpress-logo-small.png" alt="SpotsEXPRESS Services" />');
                            $('.ajax-loading-box .content').html('<h3>IMPORTANT</h3><p>Please have your order packed for labeling and shipping before you start. If you are requesting a pick up that is different from your current location, please notify the sender to have the package ready. </p><div class="ajax-notification-buttons two"><a class="ajax-notification-confirm button-red">Let\'s Do It</a><a class="ajax-notification-decline button-grey">I\'m Not Ready Yet</a></div>');
                            $('.ajax-loading-box').fadeIn();
                            $('.ajax-notification-confirm').click(function () {
                                $('.hub-bottom input[type=submit]').hide();
                                $('#ajax-loading-bar').show();
                                $('#ajax-notification, .ajax-loading-box').fadeOut();
                                $('.order-form form').append('<input type="hidden" class="discard-submit" name="discard" value="submit" />').submit();
                                $('.discard-submit').remove();
                            });*/
                        });                        
                    });
                } else {
                    $('.order-form form').submit();
                }
                e.stopPropagation();
                return false;
            });
        </script>
    }
</div>
